// custom-tab-bar/index.js
const i18nStore = require('../stores/i18n-store')

Component({
  data: {
    selected: 0,
    color: "#7A7E83",
    selectedColor: "#3cc51f",
    list: []
  },
  
  lifetimes: {
    attached() {
      this.updateTabBarData()
      // 监听语言变化
      i18nStore.intl.on('language:changed', () => {
        this.updateTabBarData()
      })
    }
  },

  methods: {
    updateTabBarData() {
      const list = [
        {
          pagePath: "/pages/index/index",
          iconPath: "/images/tabbar/home.svg",
          selectedIconPath: "/images/tabbar/home-active.svg",
          text: i18nStore.intl.t('tabbar.home')
        },
        {
          pagePath: "/pages/profile/profile", 
          iconPath: "/images/tabbar/profile.svg",
          selectedIconPath: "/images/tabbar/profile-active.svg",
          text: i18nStore.intl.t('tabbar.profile')
        }
      ]
      
      this.setData({
        list
      })
    },

    switchTab(e) {
      const data = e.currentTarget.dataset
      const url = data.path
      wx.switchTab({ url })
      this.setData({
        selected: data.index
      })
    }
  }
})